package com.oa.office.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.spring.annotation.MapperScan;

import com.oa.office.entity.HeadRouting;
import com.oa.office.entity.HeadRoutingWithBLOBs;

@MapperScan
public interface HeadRoutingMapper {
    @Delete({
        "delete from head_routing",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into head_routing (id, head_name, ",
        "day, week, creater, ",
        "create_time, updater, ",
        "updatetime, state, ",
        "spar, routing, ",
        "other)",
        "values (#{id,jdbcType=INTEGER}, #{headName,jdbcType=VARCHAR}, ",
        "#{day,jdbcType=TIMESTAMP}, #{week,jdbcType=CHAR}, #{creater,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updater,jdbcType=VARCHAR}, ",
        "#{updatetime,jdbcType=TIMESTAMP}, #{state,jdbcType=INTEGER}, ",
        "#{spar,jdbcType=VARCHAR}, #{routing,jdbcType=LONGVARCHAR}, ",
        "#{other,jdbcType=LONGVARCHAR})"
    })
    int insert(HeadRoutingWithBLOBs record);

    @InsertProvider(type=HeadRoutingSqlProvider.class, method="insertSelective")
    int insertSelective(HeadRoutingWithBLOBs record);

    @Select({
        "select",
        "id, head_name, day, week, creater, create_time, updater, updatetime, state, ",
        "spar, routing, other",
        "from head_routing",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="head_name", property="headName", jdbcType=JdbcType.VARCHAR),
        @Result(column="day", property="day", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="week", property="week", jdbcType=JdbcType.CHAR),
        @Result(column="creater", property="creater", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updater", property="updater", jdbcType=JdbcType.VARCHAR),
        @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="state", property="state", jdbcType=JdbcType.INTEGER),
        @Result(column="spar", property="spar", jdbcType=JdbcType.VARCHAR),
        @Result(column="routing", property="routing", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="other", property="other", jdbcType=JdbcType.LONGVARCHAR)
    })
    HeadRoutingWithBLOBs selectByPrimaryKey(Integer id);
    
    @Select({
        "select",
        "id, head_name, day, week, creater, create_time, updater, updatetime, state, ",
        "spar, routing, other",
        "from head_routing",
        "where (SELECT CONVERT(`day`,date)) = #{day}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="head_name", property="headName", jdbcType=JdbcType.VARCHAR),
        @Result(column="day", property="day", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="week", property="week", jdbcType=JdbcType.CHAR),
        @Result(column="creater", property="creater", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updater", property="updater", jdbcType=JdbcType.VARCHAR),
        @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="state", property="state", jdbcType=JdbcType.INTEGER),
        @Result(column="spar", property="spar", jdbcType=JdbcType.VARCHAR),
        @Result(column="routing", property="routing", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="other", property="other", jdbcType=JdbcType.LONGVARCHAR)
    })
    HeadRoutingWithBLOBs selectByDay(String day);
    
    @Select({
        "select",
        "id, head_name, day, week, creater, create_time, updater, updatetime, state, ",
        "spar, routing, other",
        "from head_routing",
        "where (SELECT WEEKOFYEAR(`day`)) = #{spar,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="head_name", property="headName", jdbcType=JdbcType.VARCHAR),
        @Result(column="day", property="day", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="week", property="week", jdbcType=JdbcType.CHAR),
        @Result(column="creater", property="creater", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updater", property="updater", jdbcType=JdbcType.VARCHAR),
        @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="state", property="state", jdbcType=JdbcType.INTEGER),
        @Result(column="spar", property="spar", jdbcType=JdbcType.VARCHAR),
        @Result(column="routing", property="routing", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="other", property="other", jdbcType=JdbcType.LONGVARCHAR)
    })
    List<HeadRoutingWithBLOBs> selectByWeek(String spar);

    @UpdateProvider(type=HeadRoutingSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(HeadRoutingWithBLOBs record);

    @Update({
        "update head_routing",
        "set head_name = #{headName,jdbcType=VARCHAR},",
          "day = #{day,jdbcType=TIMESTAMP},",
          "week = #{week,jdbcType=CHAR},",
          "creater = #{creater,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "updater = #{updater,jdbcType=VARCHAR},",
          "updatetime = #{updatetime,jdbcType=TIMESTAMP},",
          "state = #{state,jdbcType=INTEGER},",
          "spar = #{spar,jdbcType=VARCHAR},",
          "routing = #{routing,jdbcType=LONGVARCHAR},",
          "other = #{other,jdbcType=LONGVARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(HeadRoutingWithBLOBs record);

    @Update({
        "update head_routing",
        "set head_name = #{headName,jdbcType=VARCHAR},",
          "day = #{day,jdbcType=TIMESTAMP},",
          "week = #{week,jdbcType=CHAR},",
          "creater = #{creater,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "updater = #{updater,jdbcType=VARCHAR},",
          "updatetime = #{updatetime,jdbcType=TIMESTAMP},",
          "state = #{state,jdbcType=INTEGER},",
          "spar = #{spar,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(HeadRouting record);
}